<template>
  <div class="tabbar">
    <div class="content">
      <div class="logo">
        <p>微志益</p>
      </div>
      <ul>
        <router-link
          v-for="item in router"
          :key="item.path"
          :to="item.path"
          tag="li"
          active-class="router-link-active"
        >
          {{ item.name }}
        </router-link>
      </ul>

      <div class="logoinBox">
        <div class="btns" v-show="!this.isLogin">
          <router-link tag="div" to="/login">登录</router-link>
          <router-link tag="div" to="/register">注册</router-link>
        </div>
        <div class="hellow" v-show="this.isLogin">
          <span class="hy">欢迎您: {{ this.nowUser }}</span>
          <span class="mycenter" @click="toPersonal">个人中心</span>
          <span class="zx" @click="zx">注销</span>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      router: [
        { name: "首页", path: "/index" },
        { name: "捐款", path: "/money" },
        { name: "捐物", path: "/goods" },
        { name: "志愿者", path: "/volunteer"},
        { name: "寻人", path: "/find"},
        { name: "积分中心", path: "/score", },
        { name: "论坛", path: "/forum", },
      ],
      isLogin: false,
      nowUser: "",
    };
  },
  mounted() {
    if (this.$store.state.isLogin) {
      this.isLogin = true;
      // console.log(this.isLogin);
      // console.log(this.$store.state.nowUser);
      this.nowUser = this.$store.state.nowUser;
    }
  },
  methods: {
    // 注销方法
    zx() {
      this.isLogin = false;
      this.nowUser = "" 
      this.$store.state.isLogin = false
      sessionStorage.clear()
      this.$router.push("/");
    },
    toPersonal() {
      this.$router.push("/personalcenter");
    },
  },
};
</script>
<style lang="scss" scoped>
.tabbar {
  width: 100%;
  height: 100px;
  border-bottom: 2px solid #ccc;
  background: hsl(19, 100%, 58%);
  .content {
    background: hsl(19, 100%, 58%);
    width: 1200px;
    height: 100%;
    margin: auto;
    display: flex;
    position: relative;
    .logo {
      width: 180px;
      height: 100%;
      display: flex;
      img {
        width: 80px;
        height: 100%;
      }
      p {
        width: 100px;
        font-size: 28px;
        text-align: center;
        line-height: 100px;
        color: #fff;
      }
    }
    ul {
      background: hsl(19, 100%, 58%);
      color: white;
      display: flex;
      margin-left: 50px;
      li {
        font-size: 16px;
        text-align: center;
        width: 100px;
        line-height: 100px;
        cursor: pointer;
      }
      :hover {
        transition: color 0.3s;
        background: rgb(245, 84, 63);
      }
      .router-link-active {
        background-color: rgb(245, 84, 63);
        color: #fff;
      }
    }
    .logoinBox {
      position: absolute;
      right: 0;
      top: 40px;
      .btns {
        display: flex;
        color: white;
        cursor: pointer;
        div {
          padding: 0 8px;
          font-size: 14px;
        }
        :hover {
          text-decoration: underline;
        }
        :nth-child(1) {
          border-right: 1px solid #ccc;
        }
      }
      .hellow {
        .hy {
          color: #777;
          font-size: 14px;
        }
        .mycenter {
          font-size: 14px;
          color: #777;
          padding-left: 10px;
          cursor: pointer;
        }
        .mycenter:hover {
          text-decoration: underline;
          color: green;
        }
        .zx {
          color: red;
          font-size: 14px;
          padding-left: 20px;
          cursor: pointer;
        }
      }
    }
  }
}
</style>